<?php
/**
 * Created by PhpStorm.
 * User: Zhoujinda
 * Date: 2016/6/29
 * Time: 14:48
 */
namespace Mengwu\Controller;

use Mengwu\Api\MwApi;
use Shop\Api\BannersApi;
use Shop\Api\ProductGroupApi;

class ThemePavilionController extends BaseStoreController{

    public function _empty($type){
        //把所有城市的操作解析到city方法
        $this->country($type);
    }

    //主题馆
    private function country($type=false){

        $types_dt = [
            'meiguo' => 502,
            'helan' => 309,
            'aozhou' => 140,
            'riben' => 116,
            'faguo' => 305,
            'yingguo' => 303,
            'hanguo' => 133,
            'taiwan' => 150
        ];

        if(!isset($types_dt[$type])){
            $this->display_404();
        }

        $types_name = [
            'meiguo' => '美国馆',
            'helan' => '荷兰馆',
            'aozhou' => '澳洲馆',
            'riben' => '日本馆',
            'faguo' => '法国馆',
            'yingguo' => '英国馆',
            'hanguo' => '韩国馆',
            'taiwan' => '台湾馆'
        ];

        $page_no = I('p',1);
        $page_size = 16;
        $order = I('order',10);
        if(!in_array($order,[10,18,11])){
            $order = 10;
        }

        //获取轮播图
        $result = apiCall(BannersApi::QUERY_NO_PAING,[['position'=>6093]]);

        if($result['status']){
            $this->assign('banner',$result['info']);
        }

        $this->assignTitle($types_name[$type]);

        $data = [
            'page_no' => $page_no,
            'page_size' => $page_size,
            'order' => $order,
            'origin_country' => $types_dt[$type]
        ];
        $result = mwApi(MwApi::BY_Product_query,$data);

        if($result['status']){
            $product_list = $result['info']['list'];
            $PICTURE_REMOTE_URL = C('PICTURE_REMOTE_URL');
            foreach($product_list as &$val){
                $val['img'] = $PICTURE_REMOTE_URL.$val['img'].'&size=240';
            }
            $show = paging($page_no,$page_size,$result['info']['count'],'mengwu/themePavilion/'.$type);
            $this->assign('show',$show);
            $this->assign('product_list',$product_list);
            $this->assign('product_count',$result['info']['count']);
            $this->assign('country',$type);
        }

        $this->boye_display('ThemePavilion:index');
    }


}